% inpute should be AoT, and corresponding resTrees.
% for each parititon_cluster, compute information gain over each image
vol_and_cluster=AoT.vol_and_cluster;

image_score_mat = zeros(n_vol_and,n_image);
n_vol_and = numel(resTrees{i_tree});
for i_val_and = 1:n_vol_and
	resTree=resTrees{i_tree}{i_val_and};
	is_vol_and_image=(vol_and_cluster==i_val_and);
        if sum(is_vol_and_image)==0
		continue;
	end
	for iLayer = 1:numel(resTree.termLayer)
		for iNode = 1:numel(resTree.termLayer{iLayer});
			if ~strcmp(resTree.termLayer{iLayer}(iNode).type,'Term')
				continue;
			end
			possible_app_cluster = resTree.termLayer{iLayer}(iNode).shape_ind(is_vol_and_image);
			possible_app_cluster = unique(possible_app_cluster);

			for i_image = 1:n_image
				tmp_score = resTree.termLayer{iLayer}(iNode).score_map(i_image,:);
				tmp_score = max(tmp_score(possible_app_cluster));
				image_score_mat(i_val_and,i_image)=image_score_mat(i_val_and,i_image) + tmp_score;
			end

		end
	end
end

[val vol_and_cluster]=max(image_score_mat,[],1);
AoT.vol_and_cluster = vol_and_cluster;
